<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  		<script type='text/javascript'
			src='dwr/interface/courseManage.js'></script>
		<script type='text/javascript' src='dwr/engine.js'></script>
		<script type='text/javascript' src='dwr/util.js'></script>
		<style type="text/css">
			#title{
				margin-top:15px;
			}
			#table_result table{
                font-family:Georgia, "Times New Roman", Times, serif;
                border: 1px solid #555;
                color: #555;
                border-collapse: collapse;
            }
           #table_result table tr{
                	border: 1px solid #555;
                	color: #555;
            }
            #table_result table th{
                	border: 1px solid #555;
                	color: #555;
            }
           #table_result table td{
                    border: 1px solid #555;
                    color: #555;
            }
			#add_course{
				margin-left:100px;
			}
		</style>
		<SCRIPT type="text/javascript">
			function test(){
				var courseName = document.getElementById('course_name').value;
				var coursePeriod = document.getElementById('course_period').value;
				alert(courseNameError);
				var courseNameValue=courseName.value;
				if  (courseNameValue.length  ==  0)  {  
					alert("请输入课程名!");
					return  false;
					}else if(coursePeriod==0){
					alert("请输入课时!");
					}
					return  true;
		/*		alert("a");
				return false;*/
				alert();
				return false;
			}
			function checkCourseName() {
				/* get select  key*/
				var selectBox = document.getElementById('course_name');
				var selectedValue=selectBox.value;
				courseManage.searchCourseByName(selectedValue,callbackcourse);
			}
			function callbackcourse(data){
				if(data)
				document.getElementById("course_name_check").innerHTML="<span style='color:#red'>课程名已存在</span>";
				else
				document.getElementById("course_name_check").innerHTML="<span style='color:#555'>课程名可用 </span>";
					
			/*	document.getElementById("showCourseDetail").innerHTML=
					"<span style='color:#444'>" + "<span style='color:#111;'>Course:</span><br />&nbsp;cno:&nbsp;"+data.cno +
					"&nbsp;&nbsp;name:&nbsp;<b>"+data.name+"</b><br />&nbsp;describe:&nbsp;"+data.describe+"</span>";
				document.getElementById("cname_hidden").value=data.name;*/
			}
		</SCRIPT>
  </head>  
  <body>
    <div id="main">
		<s:if test="#request.add != null ">
				<div id="title"><h4><s:text name="course.text.add.course" /></h4></div><hr />
				<p><s:text name="course.text.add.please" /></p>
				<div id="add_course">
					<s:form action="course/saveCourse.action"  onsubmit="return test()"  theme="simple" >
					<table>
	    					<tr><td><s:text name="course.form.name" /></td><td><s:textfield name="course.name" key="course.form.name" id="course_name"  onchange="checkCourseName();" /></td><td id="course_name_check"><s:if test="#request.failuresave_coursenameexist != null ">课程名已存在</s:if><s:if test="#request.failuresave_coursenamenull != null ">课程名不能为空</s:if></td></tr>
	    					<tr><td><s:text name="course.form.credit" /></td><td><s:select name="course.credit" label="Credit" list="#{'1':'1','2':'2','3':'3','4':'4','5':'5','6':'6','7':'7','8':'8','9':'9','10':'10'}"></s:select></td><td></td></tr>
	    					<!-- 
	    				 	<s:textfield name="course.credit" key="course.form.credit" size="3"></s:textfield>
	    					<tr><td><s:text name="course.form.period" /></td><td><s:textfield name="course.period" key="course.form.period" id="course_period" size="3"></s:textfield></td><td id="course_name_check"></td></tr>
	    				 	-->
	    				  
	    					<tr><td><s:text name="course.form.type" /></td><td><s:select name="course.type" list="#{'1':'选修','2':'必修','3':'公共'}"></s:select></td><td id="course_name_check"></td></tr>
	    					<tr><td><s:text name="course.form.describe" /></td><td><s:textfield name="course.describe" key="course.form.describe"></s:textfield></td><td id="course_name_check"></td></tr>
	    					<tr><td></td><td><s:submit key="course.form.submit" />
	    			</table>
	    			</s:form>
    			</div>
			<div><s:if test="#request.savesuccess != null "><h4><s:text name="course.text.add.save.success" /></h4></s:if></div>
		</s:if>
		
		
				<!-- 查询课程 -->
		<s:if test="#request.search != null ">
				
			<s:if test="#request.delete != null">
				<div id="title"><h4><s:text name="course.text.delete.course" /></h4></div>
			</s:if>
			<s:else>
				<div id="title"><h4><s:text name="course.text.search.course" /></h4></div>
			</s:else>
			<hr />
			<s:if test="#request.delete != null">
				<h5><s:text name="course.text.delete.before.you.delete.course" /></h5>
			</s:if>
			<s:if test="#request.beforemodify != null ">
				<h5><s:text name="course.text.modify.before.you.modify.course" /></h5>
			</s:if>
			<div id="searchForm">
			<s:form action="course/searchCourse.action" method="post" theme="simple">                     
		           <s:submit id="sbutton"  value="Search" />
		           <s:textfield id="ssearchtext"  name="keyWord" size="22"/>
		           <div id="searchcheck">
		           		<s:radio name="searchRadio" list="#{'all':'all','no':'no','name':'name','blear':'blear'}" value="'all'" />
		           </div>
             </s:form>	
             </div>		
             	<s:if test="#request.deletesuccess != null"><h4><s:text name="course.text.delete.delete.success" /></h4></s:if>
             	<s:if test="#request.modifysuccess != null"><h4><s:text name="course.text.delete.modify.success" /></h4></s:if>
             	<s:if test="#request.searchhavedata != null ">
					<div id="table_result" >
             		<table id="searchTable" border="1">
					<tr>				
						<th><s:text name="course.text.search.cno" /></th>
						<th><s:text name="course.text.search.name" /></th>
						<th><s:text name="course.text.search.credit" /></th>
						<!-- <th><s:text name="course.text.search.period" /></th> -->
						<th><s:text name="course.text.search.type" /></th>
						<th><s:text name="course.text.search.describe" /></th>
						<s:if test="%{#session.SESSION_USERTYPE != 'instructor'}"><th><s:text name="course.text.search.modify" /></th></s:if>
						<s:if test="%{#session.SESSION_USERTYPE != 'instructor'}"><th><s:text name="course.text.search.delete" /></th></s:if>
					</tr>
					<s:iterator  value="#request.allCourse">
						<tr>
							<td><s:property value="cno"/></td>
							<td><s:property value="name"/></td>
							<td><s:property value="credit"/></td>
							<!-- <td><s:property value="period"/></td> -->
							<td><s:property value="type"/></td>
							<td><s:property value="describe"/></td>
							<s:if test="%{#session.SESSION_USERTYPE != 'instructor'}"><td><button id="sbutton" onclick="modifyCourse('<s:property value="cno"/>','<s:property value="name"/>','<s:property value="credit"/>','<s:property value="period"/>','<s:property value="type"/>','<s:property value="describe"/>');">Modify</button></td></s:if>
							<s:if test="%{#session.SESSION_USERTYPE != 'instructor'}"><td><button id="sbutton" onclick="deleteCourse('<s:property value="cno"/>');">Delete</button></td></s:if>
						</tr>
					</s:iterator>	
					</table>
					</div>						
				
				</s:if>
             	<s:if test="#request.searchnodata != null ">
             		<div id="nodata"><h4><s:text name="course.text.search.no.data" /></h4></div>
             	</s:if>
		</s:if>
		<!-- 修改课程信息, -->
           <s:if test="#request.modify != null ">
             <div id="title"><h4><s:text name="course.text.modify.course" /></h4></div><hr />
			<p><s:text name="course.text.modify.please" /></p>
			<div id="">
						<s:form action="course/modifyCourse.action"  onsubmit="return test()"  theme="simple" >
						<table>
		    					<tr><td><s:text name="course.form.name" /></td><td><s:textfield name="course.name" key="course.form.name" id="course_name"  value="%{#request.name}" onchange="checkCourseName();" /></td><td id="course_name_check"></td></tr>
		    					<tr><td><s:text name="course.form.credit" /></td><td><s:select name="course.credit" label="Credit"  value="%{#request.credit}" list="#{'1':'1','2':'2','3':'3','4':'4','5':'5','6':'6','7':'7','8':'8','9':'9','10':'10','11':'11','12':'12','13':'13','14':'14','15':'15','16':'16','17':'17','18':'18','19':'19','20':'20'}"></s:select></td><td></td></tr>
		    					<!-- 
		    				 	<s:textfield name="course.credit" key="course.form.credit" size="3"></s:textfield>
		    					<tr><td><s:text name="course.form.period" /></td><td><s:textfield name="course.period" key="course.form.period" id="course_period" size="3" value="%{#request.period}"></s:textfield></td><td id="course_name_check"><s:text name="course.form.int" /></td></tr>
		    				 	-->
		    				  
		    					<tr><td><s:text name="course.form.type" /></td><td><s:select name="course.type" list="#{'选修':'选修','2':'必修','3':'公共'}" value="%{#request.type}"></s:select></td><td id="course_name_check"></td></tr>
		    					<tr><td><s:text name="course.form.describe" /></td><td><s:textfield name="course.describe" key="course.form.describe" value="%{#request.describe}"></s:textfield></td><td id="course_name_check"></td></tr>
		    					<s:hidden name="course.cno" value="%{#request.cno}"></s:hidden>
		    					<tr><td></td><td><s:submit key="course.form.submit" />
		    			</table>
		    			</s:form>

	    	</div>
         </s:if>
	</div>
  </body>
</html>
